package com.lagou.web.servlet;


import com.alibaba.fastjson.JSON;
import com.lagou.base.BaseServlet;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;
import com.lagou.service.Impl.CourseServicelmpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet
public class CourseServlet extends BaseServlet {
    // 写方法
    public void findCourseList(HttpServletRequest req, HttpServletResponse resp){

        try {
            CourseService cs = new CourseServicelmpl();
            // 直接返回结果
            List<Course> courseList = cs.findCourseList();
            // 转json
            String s = JSON.toJSONString(courseList);
            // 响应出去
            resp.getWriter().print(s);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
